¢PowerPC NumericsContentsFigures, Tables, and ListingsAbout This BookWhat’s in This BookConventions Used in This BookSpecial FontsTypes of NotesFor More Information!The PowerPC Numerics EnvironmentIEEE Standard ArithmeticAbout the IEEE Standard'Table 1-1 Approximation of real numbers Starting to Use IEEE ArithmeticCareful Rounding Listing 1-1 Inverse operationsException Handling#Example: Finding Zero Return Values$Example: Searching Without Stopping Example: Parallel Resistances Figure 1-1 Parallel resistancesUsing IEEE ArithmeticEvaluating Continued Fractions@Figure 1-2 Graph of continued fraction functions cf(x) and rf(x) Computing the Area of a Triangle$Table 1-2 Area using Heron’s formulaAbout the FPCE Technical ReportPowerPC Numerics Versus SANEFloating-Point Data Formats !About Floating-Point Data FormatsFigure 2-1 IEEE single formatTable 2-1 Names of data types#Interpreting Floating-Point Values Normalized NumbersAFigure 2-2 Normalized single-precision numbers on the number lineDenormalized NumbersCFigure 2-3 Denormalized single-precision numbers on the number line&Table 2-2 Example of gradual underflow
Infinities5Figure 2-4 Infinities represented in single precisionNaNsTable 2-3 NaN codes0Figure 2-5 NaNs represented in single precisionZeros1Figure 2-6 Zeros represented in single precisionFormats )Table 2-4 Symbols used in format diagramsSingle FormatFigure 2-7 Single format3Table 2-5 Values of single-format numbers (32 bits)GFigure 2-8 Single-format floating-point numbers on the real number lineDouble FormatFigure 2-9 Double format3Table 2-6 Values of double-format numbers (64 bits)HFigure 2-10 Double-format floating-point values on the real number lineDouble-Double Format Figure 2-11 Double-double format/Figure 2-12 Double-double format number example$Range and Precision of Data Formats2Table 2-7 Summary of PowerPC Numerics data formatsExpression EvaluationAbout Expression Evaluation*Evaluating Expressions Without Widest Need>Figure 3-1 Evaluating complex expressions without widest need(Evaluating Expressions With Widest Need ;Figure 3-2 Evaluating complex expressions with widest need-Comparisons of Expression Evaluation Methods9Figure 3-3 Evaluating an expression with a function call>Figure 3-4 Evaluating an expression with arithmetic operationsEnvironmental ControlsRounding Direction ModesATable 4-1 Examples of rounding to integer in different directionsRounding PrecisionException FlagsInvalid Operation UnderflowOverflowDivide-by-ZeroInexactConversionsAbout Conversions,Converting Floating-Point to Integer Formats:Table 5-1 Examples of floating-point to integer conversion+Rounding Floating-Point Numbers to Integers.Converting Integers to Floating-Point Formats)Converting Between Floating-Point Formats,Converting Between Single and Double Formats:Table 5-2 Double to single conversion: Possible exceptions3Converting Between Single and Double-Double Formats.Figure 5-1 Single to double-double conversion-Figure 5-2 Double-double to single conversionATable 5-3 Double-double to single conversion: Possible exceptions3Converting Between Double and Double-Double Formats-Converting Between Binary and Decimal Numbers)Accuracy of Decimal-to-Binary ConversionsAutomatic Conversions1Figure 5-3 Conversion cycle with first-time error/Figure 5-4 Conversion cycle with correct resultManual Conversions8Converting Between Floating-Point and Decimal Structures6Converting Between Floating-Point and Decimal Strings Numeric Operations and FunctionsComparisons $Comparisons With NaNs and InfinitiesComparison OperatorsTable 6-1 Comparison symbolsArithmetic Operations $Table 6-2 Arithmetic operations in C+3Table 6-3 Special cases for floating-point addition–6Table 6-4 Special cases for floating-point subtraction*9Table 6-5 Special cases for floating-point multiplication/3Table 6-6 Special cases for floating-point divisionsqrt6Table 6-7 Special cases for floating-point square rootremainder, remquo, and fmod&Figure 6-1 Integer-division algorithm4Table 6-8 Special cases for floating-point remainderrint;Table 6-9 Special cases for floating-point round-to-integerTable 6-10 Examples of rint Auxiliary Functions Transcendental Functions&The PowerPC Numerics C ImplementationNumeric Data Types in CC Data Types Table 7-1 Names of data typesEfficient Type Declarations$Table 7-2 float_t and double_t typesInquiries: Class and Sign'Table 7-3 Class and sign inquiry macrosCreating Infinities and NaNsNumeric Data Types SummaryEnvironmental Control Functions"Controlling the Rounding Direction-Table 8-1 Rounding direction modes in MathLib
fegetround
fesetroundControlling the Exception Flags3Table 8-2 Floating-point exception flags in MathLibfeclearexceptfegetexceptferaiseexceptfesetexceptfetestexcept(Accessing the Floating-Point EnvironmentfegetenvfeholdexceptfesetenvfeupdateenvEnvironmental Controls SummaryConversion Functions,Converting Floating-Point to Integer Formatsrinttol0Table 9-1 Special cases for the rinttol function roundtol1Table 9-2 Special cases for the roundtol function+Rounding Floating-Point Numbers to Integersceil-Table 9-3 Special cases for the ceil functionfloor.Table 9-4 Special cases for the floor function
nearbyint2Table 9-5 Special cases for the nearbyint functionround.Table 9-6 Special cases for the round functiontrunc.Table 9-7 Special cases for the trunc function-Converting Integers to Floating-Point Formats*Converting Between Floating-Point Formats-Converting Between Binary and Decimal Numbers;Table 9-8 Format of decimal output string in floating style8Table 9-9 Format of decimal output string in fixed styledec2numnum2dec"Converting Between Decimal Formatsdec2strListing 9-1 Accounting programstr2decListing 9-2 Scanning algorithm8Table 9-10 Examples of conversions to decimal structuresConversions SummaryTranscendental FunctionsComparison Functionsfdim.Table 10-1 Special cases for the fdim functionfmax.Table 10-2 Special cases for the fmax functionfmin.Table 10-3 Special cases for the fmin function relation2Table 10-4 Special cases for the relation functionSign Manipulation Functions copysign2Table 10-5 Special cases for the copysign functionfabs.Table 10-6 Special cases for the fabs functionExponential Functionsexp-Table 10-7 Special cases for the exp functionexp2.Table 10-8 Special cases for the exp2 functionexpm1/Table 10-9 Special cases for the expm1 functionldexp1Table 10-10 Special cases for the ldexp function pow.Table 10-11 Special cases for the pow functionscalb0Table 10-12 Special cases for the scalb functionLogarithmic Functions frexp0Table 10-13 Special cases for the frexp functionlog.Table 10-14 Special cases for the log functionlog100Table 10-15 Special cases for the log10 functionlog1p0Table 10-16 Special cases for the log1p functionlog2/Table 10-17 Special cases for the log2 functionlogb/Table 10-18 Special cases for the logb functionmodf/Table 10-19 Special cases for the modf functionTrigonometric Functionscos.Table 10-20 Special cases for the cos functionsin.Table 10-21 Special cases for the sin functiontan.Table 10-22 Special cases for the tan functionacos/Table 10-23 Special cases for the acos functionasin/Table 10-24 Special cases for the asin functionatan/Table 10-25 Special cases for the atan functionatan20Table 10-26 Special cases for the atan2 functionHyperbolic Functionscosh/Table 10-27 Special cases for the cosh functionsinh/Table 10-28 Special cases for the sinh functiontanh/Table 10-29 Special cases for the tanh functionacosh0Table 10-30 Special cases for the acosh functionasinh0Table 10-31 Special cases for the asinh functionatanh0Table 10-32 Special cases for the atanh functionFinancial Functionscompound3Table 10-33 Special cases for the compound functionannuity2Table 10-34 Special cases for the annuity functionError and Gamma Functionserf.Table 10-35 Special cases for the erf functionerfc/Table 10-36 Special cases for the erfc functiongamma0Table 10-37 Special cases for the gamma functionlgamma1Table 10-38 Special cases for the lgamma functionMiscellaneous Functions nextafter5Table 10-39 Special cases for the nextafter functionshypot0Table 10-40 Special cases for the hypot functionrandomx!Transcendental Functions Summary&Numerics in PowerPC Assembly Language*Introduction to Assembly-Language Numerics#PowerPC Floating-Point ArchitectureFloating-Point Data FormatsFloating-Point Registers)Floating-Point Special-Purpose RegistersThe Machine State RegisterFloating-Point InstructionsLoad and Store Instructions5Table 11-1 Load and store floating-point instructions1Numerics Example Using PowerPC Assembly Language#Listing 11-1 Polynomial evaluation(Assembly-Language Environmental ControlsThe Floating-Point Environment.The Floating-Point Status and Control Register>Figure 12-1 Floating-Point Status and Control Register (FPSCR)+Table 12-1 Bit assignments for FPSCR fieldsThe Condition RegisterFigure 12-2 Condition Register;Table 12-2 Branch instructions using the Condition RegisterInquiries: Class and Sign/Floating-Point Result Flags and Condition Codes.Table 12-3 Values for FPSCR bits 15 through 19Example: Determining ClassEListing 12-1 Determining the class of an assembler instruction resultSetting the Rounding Direction/Table 12-4 Rounding direction bits in the FPSCRFloating-Point ExceptionsException Bits in the FPSCR5Table 12-5 Floating-point exception bits in the FPSCR1Signaling and Clearing Floating-Point Exceptions1Enabling and Disabling Floating-Point Exceptions%Testing for Floating-Point ExceptionsAListing 12-2 Testing for occurrence of floating-point exceptions4Saving and Restoring the Floating-Point Environment5Figure 12-3 SRC and DST fields for mtfsf instruction@Listing 12-3 Saving and restoring the floating-point environment%Assembly-Language Numeric Conversions2Conversions From Integer to Floating-Point FormatsNListing 13-1 Converting a number from integer format to floating-point format2Conversions From Floating-Point to Integer Formats(Conversions From Single to Double Format(Conversions From Double to Single Format$Assembly-Language Numeric OperationsComparison OperationsArithmetic OperationsArithmetic InstructionsMultiply-Add InstructionsMove Instructions'Transcendental and Auxiliary Functions
AppendixesSANE Versus PowerPC Numerics 'Comparison of SANE and PowerPC NumericsFloating-Point Data Formats Conversions Expression Evaluation *Infinities, NaNs, and Denormalized Numbers$Arithmetic and Comparison OperationsEnvironmental Controls%Transcendental (Elementary) Functions Porting SANE to PowerPC Numerics!Replacing Variables of Type comp )Using MathLib Instead of the SANE Library#Replacing Extended Format VariablesUsing MathLib Functions'Differences in Transcendental Functions'Differences in Class and Sign Inquiries9Table A-1 Class and sign inquiries in SANE versus MathLib&Differences in Environmental Controls?Table A-2 Environmental access functions in SANE versus MathLibEListing A-1 Using environmental controls in SANE and PowerPC NumericsCompatibility Tools in MathLibPortable Declarations*Table A-3 float_t and double_t definitionsMacros%Porting Programs to PowerPC Numerics"Semantics of Arithmetic EvaluationMixed Formats Floating-Point Precision The Rules of EvaluationThe Invalid ExceptionMathLib Header Files!Floating-Point Header File (fp.h)0Floating-Point Environment Header File (fenv.h)#FPCE Recommendations for CompilersEnvironmental Access SwitchContraction Operator Switch$Hexadecimal Floating-Point Constants,Implementing an Expression Evaluation Method)Expression Evaluation Without Widest Need'Expression Evaluation With Widest Need"Floating-Point Constant Evaluation#Initializing Floating-Point Objects.Compiler Extensions for Expression Evaluation,Determining the Expression Evaluation MethodWidening for EfficiencyMathLib ReferenceFloating-Point Data Formats&Figure E-1 Floating-point data formats,Table E-1 Interpreting floating-point values'Table E-2 Class and sign inquiry macrosEnvironmental ControlsTable E-3 Environmental access#Table E-4 Floating-point exceptions"Table E-5 Rounding direction modesOperations and FunctionsTable E-6 Arithmetic operations%Table E-7 Conversions to integer type7Table E-8 Conversions to integer in floating-point type8Table E-9 Conversions between binary and decimal formats.Table E-10 Conversions between decimal formats Table E-11 Comparison operations&Table E-12 Sign manipulation functions Table E-13 Exponential functions Table E-14 Logarithmic functions"Table E-15 Trigonometric functionsTable E-16 Hyperbolic functionsTable E-17 Financial functions$Table E-18 Error and gamma functions"Table E-19 Miscellaneous functions-PowerPC Assembly-Language Numerics ReferenceFloating-Point Data Formats&Figure F-1 Floating-point data formats,Table F-1 Interpreting floating-point values+Floating-Point Status and Control Register*Table F-2 Bit assignments for FPSCR fields.Table F-3 Rounding direction bits in the FPSCR2Table F-4 Class and sign inquiry bits in the FPSCRInstructionsTable F-5 FPSCR instructionsTable F-6 Load instructionsTable F-7 Store instructions'Table F-8 Conversions to integer format2Table F-9 Conversions from double to single format"Table F-10 Comparison instructions"Table F-11 Arithmetic instructions$Table F-12 Multiply-add instructionsTable F-13 Move instructions GlossaryBibliographyIndex